using System;
using System.Collections;
using System.ComponentModel;
using System.Security.Permissions ;
using System.Drawing.Design;
using Org.Eurekaa.DNJ.UI.Exceptions;

namespace Org.Eurekaa.DNJ.UI.WebControls
{    
	/// <summary>
    /// Summary description for MyTabPageCollection.
	/// </summary>
    /// 
    [Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor)), PermissionSet(SecurityAction.LinkDemand, XML = "<PermissionSet class=\"System.Security.PermissionSet\"\r\n               version=\"1\">\r\n   <IPermission class=\"System.Web.AspNetHostingPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\n                version=\"1\"\r\n                Level=\"Minimal\"/>\r\n</PermissionSet>\r\n")]
    public class DNJBoxCollection : CollectionBase	
	{
		#region Constructor
		public DNJBoxCollection () 
		{
		}
		#endregion Constructor

		#region Indexer
		public DNJBox this[object index]
		{
			get
			{
                
				int ind = IndexOf(index);
				if (ind < 0 )
					throw new OutOfRangeException();

				return (DNJBox) this.List[ind];				
			}
			set
			{
				this.List[IndexOf(index)] = value;
			}
		}
		#endregion Indexer

		#region Public Methods
		public void Add(DNJBox boxPage) 
		{
			this.List.Add(boxPage);
		}


		public void Insert(int index, DNJBox boxPage) 
		{
            this.List.Insert(index, boxPage);
		}

        public void Remove(DNJBox boxPage) 
		{
            this.List.Remove(boxPage);
		}

        public bool Contains(DNJBox boxPage) 
		{
            return this.List.Contains(boxPage);
		}

		//Collection IndexOf method 
		
        /// <summary>
        /// Find index of tapPage control based on ID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
		public int IndexOf(object obj) 
		{ 
			if (obj is int)
				return (int)obj;

			if (obj is string)
			{
				for (int i = 0; i < List.Count; i++)
				{
					if (((DNJBox)List[i]).ID.ToUpper() == obj.ToString().ToUpper()) 
						return i;
				}
				return -1;
			}
			else 
			{
				throw new InvalidIndexValueException();
			}			
		} 

		public void CopyTo(DNJBox[] array, int index) 
		{ 
			List.CopyTo(array, index); 
		} 
				
		public bool Contains(string key)
		{
			return List.Contains(key);
		}

		public  void Remove(string key)
		{
			List.Remove(key);
		}	
		#endregion Public Methods
    }

}